// 手机号脱敏
export function phoneNumbe(val: string) {
    return val.substr(0, 3) + '****' + val.substring(7);
}
// 定义手机号校验函数
export function validatePhoneNumber(phone: string) {
    // 手机号格式为1开头的11位数字
    const regExp = /^1\d{10}$|^(0\d{2,3}-?|\(0\d{2,3}\))?[1-9]\d{4,7}(-\d{1,8})?$/;

    if (regExp.test(phone)) {
        return true;
    } else {
        return false;
    }
}
// 节流
export const throttle = (fn: any, time: number) => {
    let timer = null;
    time = time || 1000;
    return function (...args) {
        if (timer) {
            return;
        }
        const _this = this;
        timer = setTimeout(() => {
            timer = null;
        }, time);
        fn.apply(_this, args);
    };
};

// 防抖
export const debounce = (fn: any, time: number) => {
    time = time || 200;
    // 定时器
    let timer = null;
    return function (...args) {
        const _this = this;
        if (timer) {
            clearTimeout(timer);
        }
        timer = setTimeout(function () {
            timer = null;
            fn.apply(_this, args);
        }, time);
    };
};
